home *** CD-ROM | disk | FTP | other *** search
- ---NUMBERS.DOC---
-
- Numbers and Bases
-
- A86 supports a variety of formats for numbers. In non-computer life, we
- write numbers in a decimal format. There are ten digits, 0 through 9, that
- we use to describe numbers; and each digit-position is ten times as
- significant as the position to its right. The number ten is called the
- "base" of the decimal format. Computer programmers often find it convenient to
- use other bases to specify numbers used in their programs. The most commonly-
- used bases are two (binary format), sixteen (hexadecimal format), and eight
- (octal format).
-
- The hexadecimal format requires sixteen digits. The extra six digits beyond
- 0 through 9 are denoted by the first six letters of the alphabet: A for ten,
- B for eleven, C for twelve, D for thirteen, E for fourteen, and F for fifteen.
-
- In A86, a number must always begin with a digit from 0 through 9, even if the
- base is hexadecimal. This is so that A86 can distinguish between a number and
- a symbol that happens to have digits in its name. If a hexadecimal number
- would begin with a letter, you precede the letter with a zero. For example,
- hex A0, which is the same as decimal 160, would be written 0A0.
-
- Because it is necessary for you to append leading zeroes to many hex numbers,
- and because you never have to do so for decimal numbers, I decided to make
- hexadecimal the default base for numbers with leading zeroes. Decimal is still
- the default base for numbers beginning with 1 through 9.
-
- The default base can be overridden, with a letter or letters at the end of the
- number: B or xB for binary, O or Q for octal, H for hexadecimal, and D or xD for
- decimal. Examples:
-
- 077Q octal, value is 8*7 + 7 = 63 in decimal notation
- 123O octal, if that last "O" is a letter: 64 + 2*8 + 3 = 83 decimal
- 1230 decimal 1230, illustrating why you should use "Q" for octal!!
- 100D superfluous D indicates decimal base
- 0100D hexadecimal number 100D, which is 4096 + 13 = 5009 in decimal
- 0100xD decimal 100, since the xD overrides the default hex-format
- 0110B hexadecimal 110B, which is 4096 + 256 + 11 = 5263 in decimal
- 0110xB binary 4+2 = 6 in decimal notation
- 110B also binary 4+2 = 6, since "B" is not a decimal-digit
-
- The last five examples above illustrate why an "x" is sometimes necessary
- before the base-override letter "B" or "D". If that letter can be interpreted
- as a hex digit, it is; the "x" forces an override-interpretation for the "B"
- or "D". By the way, the usage of lower-case for x and upper-case for the
- following override-letter is simply a recommendation; A86 always treats upper-
- and lower-case letters equivalently.
-
-
- The RADIX Directive
-
- The above-mentioned set of defaults (hex if leading zero, decimal otherwise)
- can be overridden with the RADIX directive. The RADIX directive consists of the
- word RADIX followed by a number from 2 to 16. The default base for the number
- is ALWAYS decimal, regardless of any (or no) previous RADIX commands. The
- number gives the default base for ALL subsequent numbers, up to (but not
- including) the next RADIX command. If there is no number following RADIX, then
- A86 returns to its initial mixed-default of hex for leading zeroes, decimal for
- other leading digits.
-
- For compatibility with IBM's assembler, RADIX can appear with a leading period;
- although I curse the pinhead-designer who put that period into IBM's language.
-
- Following are examples of radix usage. The numbers in the comments are all in
- decimal notation.
-
- DB 10,010 ; produces 10,16 if RADIX was not seen yet
- RADIX 10
- DB 10,010 ; produces 10,10
- RADIX 16
- DB 10,010 ; produces 16,16
- RADIX 2
- DB 10,01010 ; produces 2,10
- RADIX 3 ; for Martian programmers in Heinlein novels
- DB 10,100 ; produces 3,9
- RADIX
- DB 10,010 ; produces 10,16
-